package org.text2diagram.nlp.opennlp;

import java.io.IOException;

import opennlp.tools.lang.english.Tokenizer;
import opennlp.tools.tokenize.TokenizerME;

import org.text2diagram.nlp.core.NLPDetector;
import org.text2diagram.nlp.core.NLPException;

public class OpenNLPTokenDetector implements NLPDetector<String, String[]> {

	/**
	 * Instance of OpenNLPSentence detector.
	 * TODO: lazy load.
	 */
	private static OpenNLPTokenDetector detector = new OpenNLPTokenDetector();

	/**
     * English token detector.
     */
	private TokenizerME tokenizer;

    /**
     * Get sentence detector instance.
     * @return
     */
    public static OpenNLPTokenDetector getInstance() {
    	return detector;
    }

    /**
     * Initialize sentence detector instance.
     */
	private OpenNLPTokenDetector() {
		super();
		try {
			tokenizer = new Tokenizer("resources/models/opennlp/english/tokenize/EnglishTok.bin.gz");
		} catch (IOException e) {
			//TODO: correct catch
			e.printStackTrace();
		}
	}

	@Override
	public String[] detect(String data) throws NLPException {
		return tokenizer.tokenize(data);
	}

}
